package cn.droidlover.xdroidmvp.net.diy;

import org.json.JSONObject;

/**
 * Created by CLJZ on 2016/9/28.
 * 解密结果
 */
public class Base64Utils {

    /**
     * 解密结果
     */
    public static JSONObject deCode(String string) {
        JSONObject js = null;
        try {
            JSONObject jsonObject = new JSONObject(string);
            String a = getReverse(Base64.decode(jsonObject.optString("code")));
            js = new JSONObject(Base64.decode(a));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return js;
    }

    public static String deCodeString(String string) {
        String js = null;
        try {
            JSONObject jsonObject = new JSONObject(string);
            String a = getReverse(Base64.decode(jsonObject.optString("code")));
            js = Base64.decode(a);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return js;
    }

    public static String getReverse(String s) {
        StringBuffer sb = new StringBuffer(s);
        sb = sb.reverse();
        return sb.toString();
    }

    /**
     * 参数加密
     */
    public static String enCode(String json) {
        String param = Base64.encode(Base64.decode(Base64.encode(json.toString())));
        String reverse = Base64.encode(getReverse(param));
        return reverse;
    }
}
